package com.yanqu.road.handle;

import com.yanqu.road.AgentServer;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.player.Player;
import com.yanqu.road.player.PlayerControl;
import com.yanqu.road.task.AgentCommandTask;
import io.netty.channel.ChannelHandlerContext;

public class AgentMsgHandle {
    public static void handleMsg(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) {
        long playerId = yanQuMessage.getPlayerId();
        Player player = PlayerControl.getOnlinePlayer(playerId);
        AgentCommandTask commandTask = new AgentCommandTask(ctx, yanQuMessage, player);

        if (null != player) {//玩家队列
            player.getCommandQueue().add(commandTask);
        } else {
            AgentServer.getServerCommandExecutor().execute(commandTask);
        }
    }
}
